618B - Guess the Permutation - CodeForces Solution


constructive algorithms *1100

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define int long long
#define mod  1000000007
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fill(a,b) memset(a,b,sizeof(a))
void solve()
{
    int n;cin>>n;
    vector<pair<int,map<int,int>>>v(n);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            int x;cin>>x;
            v[i].ss[x]++;
        }
    }
    int b[n]={0};
    int vis[n+1]={0};
    for(int i=0;i<n;i++)
    {
        for(auto it:v[i].ss)
        {
            if(it.ss>1)
            {
                b[i]=it.ff;
                vis[it.ff]++;
                break;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        if(b[i]==0)
        {
            for(int j=1;j<=n;j++)
            {
                if(vis[j]==0)
                {
                    b[i]=j;
                    vis[j]++;
                    break;
                }
            }
        }
    }
    for(auto it:b)cout<<it<<" ";
    cout<<endl;
}
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

1566B - MIN-MEX Cut
678C - Joty and Chocolate
1352E - Special Elements
1520E - Arranging The Sheep
1157E - Minimum Array
1661D - Progressions Covering
262A - Roma and Lucky Numbers
1634B - Fortune Telling
1358A - Park Lighting
253C - Text Editor
365B - The Fibonacci Segment
75A - Life Without Zeros
1519A - Red and Blue Beans
466A - Cheap Travel
659E - New Reform
1385B - Restore the Permutation by Merger
706A - Beru-taxi
686A - Free Ice Cream
1358D - The Best Vacation
1620B - Triangles on a Rectangle
999C - Alphabetic Removals
1634C - OKEA
1368C - Even Picture
1505F - Math
1473A - Replacing Elements
959A - Mahmoud and Ehab and the even-odd game
78B - Easter Eggs
1455B - Jumps
1225C - p-binary
1525D - Armchairs